{* $Id$ *}
{include_core file="admin/lib/header.html" title="掌柜订单列表"}
<style type="text/css">
  .list-table tbody tr td .btn{
      font-size: 14px;
  }
</style>
  <div class="page-header border-bottom clearfix">
    <h2 class="left">{if $status == 0}回收{/if}掌柜订单管理<span>在这里对{if $status == 0}回收{/if}掌柜订单进行管理</span></h2>
    {if $status == 1}
      {* <a href="{AnUrl('order/admin/store_order?status=0')}" class="btn btn-success btn-sm right"><i class="icon-add"></i>回收站</a> *}
    {else}
    <a href="{AnUrl('order/admin/store_order?status=1')}" class="btn btn-default btn-sm right">&lt; 返回掌柜订单列表</a>
    {/if}
    {if user_config::ADMIN == $role_id}
     {* <a style="margin-top:5px; display:block; float:right;" href="{get_url()}&is_excel=1" class="btn btn-xs btn-primary js_downList">导出EXCEL</a>  *}
    {/if}
  </div>
  <div class="search-form js_advancedForm">
    <form action="{AnUrl('order/admin/marketing_order_list')}" method="get" class="js_orderSearchForm">
      <input type="hidden" name="status" value="{$status}">
      <input type="hidden" name="type" value="{$type}">
      <p>
        <label for="" class="search-f-label">订单编号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[order_code]" value="{$search_filter.order_code}">
      </p>
      <p>
        <label for="" class="search-f-label">掌柜手机：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[mobile]" value="{$search_filter.mobile}">
      </p>
      <!-- <p>
        <label for="" class="search-f-label">订单状态：</label>
        <select class="search-f-slt1" name="search_filter[progress]">
          <option value="-1" {if $search_filter.progress == '-1'}selected{/if}>全部</option>
          {foreach order_config::$store_progress as $k=>$v}
            <option value="{$k}" {if $search_filter.progress && $search_filter.progress == $k}selected{/if}>{$v}</option>
          {/foreach}
        </select>
      </p> -->
      <p>
      <label for="" class="search-f-label">添加时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>
  <!--start:列表-->
  <table class="list-table goods-table">
    <!-- <caption>按&nbsp;&nbsp;状&nbsp;&nbsp;态：
      <a href='{AnUrl("order/admin/store_order")}' {if $progress == -1 && $status == 1} class="label label-primary" {else} class="label label-default" {/if}>全部订单</a>
      {foreach order_config::$store_progress as $k=>$v}
        <a href='{AnUrl("order/admin/store_order?progress={$k}&type={$type}&task_user_id=$task_user_id")}' {if $progress == $k && $status == 1} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
      {/foreach}
        <a href='{AnUrl("order/admin/store_order?status=0&task_user_id=$task_user_id")}' {if $status == 0} class="label label-primary" {else} class="label label-default" {/if}>已删除</a>
    </caption> -->
    {$order_type_list = order_config::$order_type}
    <thead>
      <tr>
        <th style="min-width:100px;">订单编号</th>
        <th style="min-width:250px;">商品</th>
        <th style="width:30px;">单价(元)</th>
        <th style="width:30px;">实际需支付(元)</th>
        <th style="width:30px;">数量</th>
        <th style="width:30px;">总数</th>
        <th style="width:30px;">总价(元)</th>
        <th style="min-width:150px;">掌柜信息</th>
        <th style="min-width:150px;">市场人员信息(员工信息)</th>
<!--         <th style="width:50px;">市场人员设备类型</th>
       <th style="width:50px;">交易状态</th>
       <th>操作</th> -->
      </tr>
    </thead>
    <tbody>
      {foreach $order_list as $k=>$v}
        {$order_count = count($v.order_relation)}
        {foreach $v.order_relation as $key=>$order_relation_info}
          <tr data-id="{$v.id}" id="dataList{$v.id}">
            {if $key == 0}
              <td rowspan="{$order_count}">
                订&nbsp;&nbsp;单&nbsp;&nbsp;号：{order_helper::order_id_encode($v.id)}<br />
                下单时间：{$v.add_time}<br />
                {if $v.task_user_id}代理下单：{user_helper::display_name($v.task_user_id)}<br />{/if}
                {if $v.task_desc}代理备注：{$v.task_desc}<br />{/if}
                {if $v.transaction_id}
                交易号:<br />{$v.transaction_id}
                {/if}
              </td>
            {/if}
            {$goods_info = goods_helper::get_goods_info($order_relation_info['goods_id'])}
            <td>分类：{_uri('category', $goods_info['category_id'], 'title')}
            <br/>商品名称：{$goods_info['title']}&nbsp;&nbsp;
            <br/>商品简介：{$goods_info['intro']}</td>
            <td>{$order_relation_info.goods_price}</td>
            <td>{$order_relation_info.real_price}</td>
            <td>{$order_relation_info.goods_num}</td>
            {if $key == 0}
              <td rowspan="{$order_count}">{$v.goods_num}</td>
              <td rowspan="{$order_count}">{$v.price}</td>
              <td rowspan="{$order_count}">
                {if $v.pay_time != '0000-00-00 00:00:00'}
                <p>支付时间：{$v.pay_time}</p>
                <p>　</p>
                {/if}
                {$user_info = user_helper::get_user_info($v.user_id)}
                <p>收货人：{$user_info.realname}</p>
                <p>电话：{$user_info.mobile}</p>
                {*<p>收货地址：<span>{$v.province} {$v.city} {$v.district} {$v.address}</span></p>
                {if $v.invoice_title}
                <p>发票：<span>{$v.invoice_title}({order_config::$invoice_type[$v.invoice_type]})</span></p>
                {/if}
                {$express_title = _uri('express',$v.express_id,'title')}
                <p>物流公司：{$express_title}</p>
                {if $v.express_no}
                <p>物流单号：{$v.express_no}</p>
                {/if}
                {if $v.deliver_type}
                <p>配送时间：{order_config::$deliver_type[$v.deliver_type]}</p>
                {/if}*}
              </td>
              <td>
                <p>市场人员姓名:<br/>{$v.marketing_info.realname}</p>
                <p>市场人员手机号:<br/>{$v.marketing_info.mobile}</p>
              </td>
              <!-- <td>
                {if $v.source == 0}
                    <span class="label label-warning">{$v.source_str}</span>
                {elseif $v.source == 1}
                    <span class="label label-danger">{$v.source_str}</span>
                {elseif $v.source == 2}
                    <span class="label label-success">{$v.source_str}</span>
                {else}
                    <span class="label label-info">{$v.source_str}</span>
                {/if}
              </td> -->
              {$order_progress_list = order_config::$store_progress}
              <!-- <td rowspan="{$order_count}">
                {if $v.progress == 1}
                  <span class="label label-warning">{$order_progress_list[$v.progress]}</span>
                {elseif $v.progress == 10}
                  <span class="label label-success">{$order_progress_list[$v.progress]}</span>
                {elseif $v.progress == 15}
                  <span class="label label-default">{$order_progress_list[$v.progress]}</span>
                {else}
                  <span class="label label-info">{$order_progress_list[$v.progress]}</span>
                {/if}
              </td> -->
              <!-- <td>
                {if $role_id == user_config::ADMIN || $role_id == user_config::OPERATOR}
                  {if $status}
                    <a href="{AnUrl("order/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs js_deleteOrder"><i class="icon-trash icon-white"></i>删除订单</a>
                  {else}
                    <a href="{AnUrl("order/admin/change_status?id={$v.id}")}" class="btn btn-warning btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>还原</a>
                  {/if}
                {/if}
                {if $role_id == user_config::ADMIN || $role_id == user_config::OPERATOR || $role_id == user_config::ASSISTANT}
                  {if $v.progress == 5}
                    <a href="{AnUrl("order/admin/store_order/finish_store_order?id={$v.id}")}" class="btn btn-danger btn-xs js_finishStoreOrder"><i class="icon-trash icon-white"></i>确认送达</a>
                  {/if}
                {/if}
              </td> -->
            {/if}
              
          </tr>
        {/foreach}
      {foreachelse}
        <tr><td class="txtleft" colspan="10">暂无数据</td></tr>
      {/foreach}
    </tbody>
  </table>
  <div class="js_expressDiv" style="display:none;">
    <div style="padding:20px;line-height:30px;">
      {foreach  $express_list as $k=>$v}
      <div class="js_expressTitle" data-id="{$v.id}">物流公司：{$v.title}</div>
      {/foreach}
      <div>物流单号：<input type="text" class="js_expressInp"></div>
    </div>
  </div>
  
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
<script>
$(function(){
  // 高级搜索时间验证
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var thisObj   = $(this);
    var startDate = $.trim($('#startDate').val());
    var stopDate  = $.trim($('#stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return;
    }
    thisObj.closest('form').submit();
  });

  //弹层取消操作
  $('.js_cancel').click(function(){
    $('.float-confirm').hide();
  })

  //触发发货事件
  $('.js_deliveryBtn').click(function(){
    var order_id = $(this).closest('tr').data('id');
    showConfirmDiv($('.js_recommendDiv'), order_id);
  })

  // 同意发货操作
  $('#js_allow').click(function(){
    var express_name = $.trim($('.js_express_name').val());
    var express_no = $.trim($('.js_express_no').val());
    var express_note = $.trim($('.js_express_note').val());
    var id = $('.js_recommendDiv').data('id');
    
    if (!express_name || express_name == '') {
      showMsg('请填写物流公司名称');
      return false;
    }
    if (!express_no) {
      showMsg('请填写物流单号');
      return false;
    }
    showMask('正在提交中...', 1);
    $.post(
      "{AnUrl('order/admin/shipping')}",
      { express_no:express_no, express_name:express_name, express_note:express_note, id:id },
      function (data){
        if (data.info != 'ok') {
          showMsg(data.info);
        }
        location.href = location.href;
      },
      'json'
    );
  });

  //触发收款按钮事件
  $('.js_payBtn').click(function(){
    var order_id = $(this).closest('tr').data('id');
    showConfirmDiv($('.js_confirm_moneyDiv'), order_id);
  });

  // 确认收款操作
  $('#js_confirm_moneyAllow').click(function(){
    var confirm_money_note = $.trim($('.js_confirm_money_note').val());
    var confirm_money_name = $.trim($('.js_confirm_money_name').val());
    var confirm_money_time = $.trim($('.js_confirm_money_time').val());

    var id = $('.js_confirm_moneyDiv').data('id');
    var params = {};
    params.id = id;
    
    if (!confirm_money_name) {
        alert('请填写收款人姓名!');
        return;
    }
    params.confirm_money_name = confirm_money_name;

    if (!confirm_money_time) {
        alert('请填写收款时间!');
        return;
    }
    params.confirm_money_time = confirm_money_time;
    
    if (confirm_money_note) {
        params.confirm_money_note = confirm_money_note;
    }
    showMask('正在提交中...', 1);
    $.post(
      "{AnUrl('order/admin/confirm_pay')}",
      params,
      function (data){
        if (data.info != 'ok') {
          showMsg(data.info);
        }
        location.href = location.href;
      },
      'json'
    );
  });
  
  // 单个订单删除
  $(".js_deleteOrder,.js_changeStatus").live('click',function(e){
    e.preventDefault();
    e.stopPropagation();
    var selectId = $(this).closest("tr").attr("id");
    var roleId = $(this).closest("tr").data("id");
    if (!selectId) {
      alert('请选择要操作记录');
    }
    
    var clickObj = $(this);
    var url = clickObj.attr("href");
    var cardListBox = clickObj.closest('.cardListBox');
    var lines = $(this).parent().attr('rowspan');
    var notice = {if $status == 1}'确定要删除此订单吗？'{else}'确定执行此操作吗?'{/if}; 
    showConfirm(notice, 1, function(){
      $.post(url, {  'id':selectId }, function(json){
        if (json.info != 'ok') {
          alert(json.info);
        } else {
          clickObj.closest("tr").fadeOut(function(){
            if (lines) {
              for (var i = 1; i < lines; i++) {
                $(this).next().remove();
              }
            };
            $(this).remove();
            interLineColor();
            {if $status == 1}
            showMsg('删除成功!被删除订单可在回收站还原.', 1);
            {/if}
            if (cardListBox) {
              var trNum = cardListBox.find('.deleteOne').length;
              var level_total = cardListBox.attr('data-level_total');
              consoleLog(trNum);
              consoleLog(level_total);
              if (trNum < level_total) {
                $('.addCard').show();
              }
            }
            
            location.href = location.href;
          });
        }
      }, 'json');
    });
    return false;
  });
  
//单个订单删除
  $(".js_finishStoreOrder").live('click',function(e){
    e.preventDefault();
    e.stopPropagation();
    alert(2);
    var selectId = $(this).closest("tr").attr("id");
    var roleId = $(this).closest("tr").data("id");
    if (!selectId) {
      alert('请选择要操作记录');
    }
    
    var clickObj = $(this);
    var url = clickObj.attr("href");
    var cardListBox = clickObj.closest('.cardListBox');
    var lines = $(this).parent().attr('rowspan');
    var notice = '确定执行此操作吗?'; 
    showConfirm(notice, 1, function(){
      $.post(url, {  'id':selectId }, function(json){
        if (json.info != 'ok') {
          alert(json.info);
        } else {
            showMsg('操作成功!');
            
            location.href = location.href;
          });
        }
      }, 'json');
    });
    return false;
  });


  
  // added by ninghx 2012-07-31 将页面中的时间插件转移到公用的js中
/*   $('#js_confirm_money_time').datepicker({
    dateFormat: 'yy-mm-dd',
    showButtonPanel: true,
    yearRange: '1900:'+new Date().getFullYear(),
    changeYear:true,
    changeMonth:true,
    maxDate: new Date(),
    yearSuffix: ''
  }); */
  
  //取消订单事件
  $('.js_cancelOrderBtn').click(function(){
    var order_id = $(this).closest('tr').data('id');
    showConfirmDiv($('.js_cancelOrderDiv'), order_id);
  });

  //同意取消订单操作
  $('#js_cancelOrderAllow').click(function(){
    var order_reason = $.trim($('.js_cancelOrderReason').val());
    var id = $('.js_cancelOrderDiv').data('id');
    
    if (!order_reason || order_reason == '') {
      showMsg('请填写取消订单的理由');
      return false;
    }
    
    showMask('正在提交中...', 1);
    
    $.post(
      "{AnUrl('order/admin/cancel_order')}",
      { order_reason:order_reason, id:id },
      function (data){
        if (data.info != 'ok') {
          showMsg(data.info);
        }
        location.href = location.href;
      },
      'json'
    );
  });

  function showConfirmDiv(obj, id) {
    var width = $(window).width();
    var height = $(window).height();
    var divWidth = parseInt(obj.css('width'));
    var divHeight = parseInt(obj.css('height'));
    var leftWidth = (width - divWidth) / 2;
    var topHeight = $(window).scrollTop()+(height - divHeight) / 2;
    obj.css({ left:leftWidth+'px', top:topHeight+'px' }).attr('data-id', id).show();
  }
});
</script>
<div class="float-confirm js_recommendDiv" style="z-index: 20000;display: none; width:auto;">
  <div class="float-confirm-con">
    <p style="font-size:18px;color:#23a18b;">输入物流编号发货</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;height:auto;margin-bottom:15px;">
      <table style="line-height:50px;" class="js_expressTable">
        <tr>
          <td><span style="color:red;">*</span>物流公司：</td>
          <td style="min-width:400px;">
            {*<select class="js_express_code">
              <option value="0">请选物流递公司</option>
              {foreach $express_list as $v}
              <option value="{$v.id}">{$v.title}</option>
              {/foreach}
            </select>*}
            <input type="text" name="express_name" class="js_express_name">
          </td>
        </tr>
        <tr>
          <td><span style="color:red;">*</span>物流编号：</td>
          <td style="min-width:400px;">
            <input type="text" name="express_no" class="js_express_no">
          </td>
        </tr>
        <tr>
          <td>备注：</td>
          <td style="min-width:400px;">
            <textarea name="express_note" class="add-f-area textarea_box js_express_note"></textarea>
          </td>
        </tr>
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div class="float-confirm-btns" style="padding-bottom:30px;">
      <a id="js_allow" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
      <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
    </div>
  </div>
</div>
<div class="float-confirm js_confirm_moneyDiv" style="z-index: 20000;display: none; width:auto;">
  <div class="float-confirm-con">
    <p style="font-size:18px;color:#23a18b;">输入收款备注</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;height:auto;margin-bottom:15px;">
      <table style="line-height:50px;" class="js_expressTable">
      <tr>
          <td><span style="color:red;">*</span>收款人：</td>
          <td style="min-width:400px;">
            <input type="text" class="search-f-ipt1 js_confirm_money_name" name="" value="">
          </td>
        </tr>
         <tr>
          <td><span style="color:red;">*</span>收款时间：</td>
          <td style="min-width:400px;">
             <input type="text" class="search-f-ipt1 js_confirm_money_time" id="js_confirm_money_time" name=""   value="">
          </td>
        </tr>
        <tr>
          <td>备注：</td>
          <td style="min-width:400px;">
            <textarea name="confirm_money_note" class="add-f-area textarea_box js_confirm_money_note"></textarea>
          </td>
        </tr>
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div class="float-confirm-btns" style="padding-bottom:30px;">
      <a id="js_confirm_moneyAllow" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
      <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
    </div>
  </div>
</div>
<div class="float-confirm js_cancelOrderDiv" style="z-index: 20000;display: none; width:auto;">
  <div class="float-confirm-con">
    <p style="font-size:18px;color:#23a18b;">取消订单理由</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;height:auto;margin-bottom:15px;">
      <table style="line-height:50px;" class="js_expressTable">
        <tr>
          <td>理由：</td>
          <td style="min-width:400px;">
            <textarea name="reason" class="add-f-area textarea_box js_cancelOrderReason"></textarea>
          </td>
        </tr>
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div class="float-confirm-btns" style="padding-bottom:30px;">
      <a id="js_cancelOrderAllow" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
      <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
    </div>
  </div>
</div>
<div class="float-bg" style="z-index: 19999; display: none"></div>
{include_core file="admin/lib/footer.html"}